package com.app.admin.controller;


import com.app.admin.service.SerialNumberService;
import com.app.enums.admin.LockType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author qiangt
 * @version 1.0
 * @date 2023/12/12 17:08
 * @description: 序列号controller
 */
@RestController
@RequestMapping("/v1/admin")
@Api(tags = "SerialNumber")
@RequiredArgsConstructor
public class SerialNumberController {

    private final SerialNumberService serialNumberService;

    @ApiOperation(value = "生成序列号")
    @GetMapping("/serialNumber")
    public String generateOrderSerialNumber() {
        final String group = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
        final Long usableNumber = this.serialNumberService.calculateUsableSerialNumber(LockType.OrderSerialNumber.name(), group);
        return String.format("%s-%s", group, String.format("%05d", usableNumber));
    }
}
